package com.ruoyi.web.controller.consume;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.consume.domain.SeedConsumeTemporary;
import com.ruoyi.consume.domain.SimpleConsume;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.StromaConsumeTemporay;
import com.ruoyi.consume.service.IStromaConsumeTemporayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 查看临时领用信息Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("查看临时领用信息")
@RestController
@RequestMapping("/consume/stromatemcon")
public class StromaConsumeTemporayController extends BaseController
{
    @Autowired
    private IStromaConsumeTemporayService stromaConsumeTemporayService;

    /**
     * 查询查看临时领用信息列表
     */
    @ApiOperation("查询查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:list')")
    @GetMapping("/list")
    public TableDataInfo list(StromaConsumeTemporay stromaConsumeTemporay)
    {
        startPage();
        List<StromaConsumeTemporay> list = stromaConsumeTemporayService.selectStromaConsumeTemporayList(stromaConsumeTemporay);
        return getDataTable(list);
    }

    /**
     * 导出查看临时领用信息列表
     */
    @ApiOperation("导出查看临时领用信息列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:export')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StromaConsumeTemporay stromaConsumeTemporay)
    {
        List<StromaConsumeTemporay> list = stromaConsumeTemporayService.selectStromaConsumeTemporayList(stromaConsumeTemporay);
        ExcelUtil<StromaConsumeTemporay> util = new ExcelUtil<StromaConsumeTemporay>(StromaConsumeTemporay.class);
        return util.exportExcel(list, "查看临时领用信息数据");
    }

    /**
     * 获取查看临时领用信息详细信息
     */
    @ApiOperation("获取查看临时领用信息详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:query')")
    @GetMapping(value = "/{stromaConsumeTemporayId}")
    public AjaxResult getInfo(@PathVariable("stromaConsumeTemporayId") Long stromaConsumeTemporayId)
    {
        return AjaxResult.success(stromaConsumeTemporayService.selectStromaConsumeTemporayById(stromaConsumeTemporayId));
    }

    /**
     * 新增查看临时领用信息
     */
    @ApiOperation("新增查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:add')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StromaConsumeTemporay stromaConsumeTemporay)
    {
        return toAjax(stromaConsumeTemporayService.insertStromaConsumeTemporay(stromaConsumeTemporay));
    }

    /**
     * 修改查看临时领用信息
     */
    @ApiOperation("修改查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:edit')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StromaConsumeTemporay stromaConsumeTemporay)
    {
        return toAjax(stromaConsumeTemporayService.updateStromaConsumeTemporay(stromaConsumeTemporay));
    }

    /**
     * 删除查看临时领用信息
     */
    @ApiOperation("删除查看临时领用信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:remove')")
    @Log(title = "查看临时领用信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stromaConsumeTemporayIds}")
    public AjaxResult remove(@PathVariable Long[] stromaConsumeTemporayIds)
    {
        return toAjax(stromaConsumeTemporayService.deleteStromaConsumeTemporayByIds(stromaConsumeTemporayIds));
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:stromatemcon:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<StromaConsumeTemporay> list = stromaConsumeTemporayService.getUserName();
        List<SimpleConsume> simpleConsumes = new ArrayList<>();
        for (StromaConsumeTemporay stromaConsumeTemporay:list) {
            Long id = stromaConsumeTemporay.getUserId();
            String name = stromaConsumeTemporay.getUserName();
            SimpleConsume consume = new SimpleConsume(id,name);
            simpleConsumes.add(consume);
        }
        return getDataTable(simpleConsumes);
    }
}
